<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">

    <title>Title</title>
    <link rel="stylesheet" href="/layui/lib/layui-v2.5.5/css/layui.css" media="all">
</head>
<body>
<form class="layui-form">
    <input type="hidden" name="id"value="{{ $rows->id }}">
    <div class="layui-form-item">
        <label class="layui-form-label">图片上传</label>
        <div class="layui-input-inline">
            <div class="layui-upload-drag" id="test10">
                <i class="layui-icon"></i>
                <p>点击上传，或将文件拖拽到此处</p>
                <div id="uploadDemoView">
                    <hr>
                    <img src="{{ $rows->img }}" alt="上传成功后渲染" style="max-width: 196px">
                </div>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">热门</label>
        <div class="layui-input-inline">

            <input type="radio" name="hot" value="热门" title="Yes" @if($rows->hot=="热门")checked @endif>
            <input type="radio" name="hot" value="冷门" title="NO" @if($rows->hot=='')checked @endif>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">常用服务</label>
        <div class="layui-input-inline">
            <input type="text" name="often" required lay-verify="required" placeholder="请输入服务"value="{{ $rows->often }}" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">轮播图</label>
            <div class="layui-input-inline">
                <input type="radio" name="cycle" value="1" title="Yes" @if($rows->cycle==1)checked @endif>
                <input type="radio" name="cycle" value="0" title="No" @if($rows->cycle==0)checked @endif>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">类型</label>
            <div class="layui-input-inline">
                <input type="text" name="type" required lay-verify="required" placeholder="去输入类型" value="{{ $rows->type }}" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
</form>
</body>
<script src="/layui/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="/js/xm-select.js"></script>
<script>

    layui.use(['form', 'table','jquery','upload'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table,
            upload = layui.upload;
        var image;
        //拖拽上传
        upload.render({
            elem: '#test10'
            ,url: '/admin/upload' //改成您自己的上传接口
            ,field: 'img'
            ,done: function(res){
                layer.msg('上传成功');
                layui.$('#uploadDemoView').removeClass('layui-hide').find('img').attr('src', "/"+res.msg);
                image = "/"+res.msg;
            }
        });
        form.on('submit(formDemo)', function (data) {
            var tp=$('#uploadDemoView').find('img').attr('src');
            data.field.img = tp;
            var result = data.field;
            $.ajax({
                url : "/admin/home_update",
                type : "post",
                async: false , //改为同步
                data:{'_token':'{{ csrf_token() }}',result},
                success : function(data) {
                    if(data==1){
                        parent.layer.closeAll();
                        parent.location.reload();
                    }
                },
            });
        });
    });
</script>
</html>